package com.lvzero.answer.controller;

import com.lvzero.answer.common.Result;
import com.lvzero.answer.service.AwardService;
import com.lvzero.answer.util.AwardUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 奖品的controller
 */
@Api(tags = "奖品模块")
@RestController
@CrossOrigin
@RequestMapping("api")
public class AwardController {

    @Autowired
    AwardService awardService;

    /**
     * 获取所有的奖品
     *
     * @return
     */
    @ApiOperation(value = "获取所有的奖品",httpMethod = "GET")
    @RequestMapping("award")
    public Result getAward() {
        return awardService.getAward();
    }


    /**
     * 点击抽奖获取等级
     */
    @ApiOperation(value = "获取中的是几等奖",httpMethod = "GET")
    @RequestMapping("award/level")
    public Result getLevel() {
        Result award = awardService.getAward();
        List<Map> map = award.getData();
        // AwardUtil.getIndex(map)获取的是index 所以需要+1
        return Result.success(AwardUtil.getIndex(map)+1);
    }

}
